package com.dcy.znoa.service.sys.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.dcy.znoa.common.util.pojo.JsonCommon;
import com.dcy.znoa.dao.sys.RoleAuthDao;
import com.dcy.znoa.domain.sys.OperRole;
import com.dcy.znoa.domain.sys.RoleAuth;
import com.dcy.znoa.service.sys.RoleAuthService;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RoleAuthServiceImpl implements RoleAuthService {

    @Autowired
    RoleAuthDao roleAuthDao;
    
    @Override
    public JsonCommon insert(RoleAuth roleAuth) {
        Integer result = roleAuthDao.insert(roleAuth);
        if (result == null || result <= 0) {
            return new JsonCommon(JsonCommon.INSERT_ERROR_CODE);
        }
        return new JsonCommon(JsonCommon.SUCCESS_CODE, JsonCommon.SUCCESS_MSG);
    }


	@Override
	public JsonCommon delete(Long roleId, List<Long> urlIdsList) {
		EntityWrapper<RoleAuth> ew = new EntityWrapper<>();
        ew.eq("role_id",roleId) .in("url_id", urlIdsList);
        roleAuthDao.delete(ew);       
		return new JsonCommon(JsonCommon.SUCCESS_CODE, JsonCommon.SUCCESS_MSG);
	}


	@Override
	public JsonCommon deleteByRoleId(Long roleId) {
		//先删除原有权限
		EntityWrapper<RoleAuth> ew = new EntityWrapper<>();
        ew.eq("role_id",roleId);
        roleAuthDao.delete(ew); 
        
		return new JsonCommon(JsonCommon.SUCCESS_CODE, JsonCommon.SUCCESS_MSG);
	}


}
